// filename: AsyncTcpSocket.h
// author: enic
// date: 2015-06-26

#pragma once

#include "IAsyncTcpSocket.h"
#include "SocketEngine.h"
#include "import_boost.h"

class AsyncTcpAcceptor : public IAsyncTcpAcceptor
{
public:
	AsyncTcpAcceptor(SocketEngine* pSocketEngine);
	virtual ~AsyncTcpAcceptor();

	// IAsyncTcpAcceptor
public:
	virtual void SetCloseSink(TAcceptorCloseSink closeSink);
	virtual void Close();
	virtual void Bind(const IpEndpoint& ipEndpint);
	virtual void Listen(uint32_t nMax);
	virtual void SetAcceptSink(TAcceptSink acceptSink);
	virtual void AsyncAccept();

public:
	virtual void OnAsyncAccept(IAsyncTcpSocket* pSocket);

private:
	SocketEngine* m_pSocketEngine;
	TAcceptorCloseSink m_FuncCloseSink;
	TAcceptSink m_FuncAcceptSink;
	AsyncTcpSocket* m_pTcpSocketCurAccept;

private:
	boost::asio::ip::tcp::acceptor m_acceptor;
};